#!/usr/bin/env php
<?php
$SOAR_DIR=getenv("SOAR_DIR");
if(empty($SOAR_DIR)) $SOAR_DIR="/opt/soar";
$SOAR_DIR="../../../../../..";
include "$SOAR_DIR/common/php/soar/soar.inc";

function usage()
{/*{{{*/
    print "Usage: ".basename(__FILE__)." host:port SERVICE [key:value ...]\n";
}/*}}}*/

function main($argv)
{/*{{{*/
    $selfname=basename(array_shift($argv));
    if(count($argv) < 2)
    {
        usage();
        return 1;
    }
    $addr=array_shift($argv);
    $svc=array_shift($argv);

    $request=array();
    foreach($argv as $v)
    {
        $arr=split(':', $v);
        if($arr === false || count($arr) != 2)
        {
            print "Error: para($v) invalid\n\n";
            usage();
            return 1;
        }
        $request[$arr[0]]=$arr[1];
    }
    print "----------------------------------------\n";
    print "Request:\n";
    print "$svc\n";
    print_r($request);
    print "----------------------------------------\n";

    $sn=new Svcnode($addr, Svcnode::PERMANENT);
    //for($i=0; $i<3; ++$i)
    {
        //$request=array('msg'=>str_repeat('a', 256*1024));
        $response=$sn->call("REQUEST", $svc, $request);
        if($response === false)
        {
            print "Error: svcnode call fail\n";
            return 1;
        }

        print "Response:\n";
        print_r($response);
        //print $response['errcode']."\n";
        print "----------------------------------------\n";
    }
    $sn->close();

    return 0;
}/*}}}*/

exit(main($argv));
?>
